<?php
$path = "../../image/book/";
//上传目录
$response = array();
//状态初始化
$Max_size = 1024000;
//上传最大值
$type = $_FILES['photo']['type'];
//文件类型
$tmp = $_FILES['photo']['tmp_name'];
$filename = time() . substr($_FILES['photo']['name'], strrpos($_FILES['photo']['name'], '.'));
//图片名
if ($type == "image/gif" || $type == "image/jpeg" || $type == "image/jpg" || $type == "image/pjpeg" || $type == "image/x-png" || $type == "image/png") {
    if ($Max_size > $_FILES['photo']['size']) {
        if (move_uploaded_file($tmp, $path . $filename)) {
            $response['code'] = '200';
            //状态码
            $response['src'] = $path . $filename;
            //图片地址
            $response['name'] = $filename;
            //图片名
        } else {
            $response['code'] = '500';
            //状态码
            $response['msg'] = '图片上传失败';
            //失败原因
        }
        //返回前端状态
    } else {
        $response['code'] = '500';
        $response['msg'] = '图片大小不能超过1MB';
    }
    //判断图片大小
} else {
    $response['code'] = '500';
    $response['msg'] = '请上传图片';
}
//文件类型判断
echo json_encode($response);
//返回前端状态，转换成json对象